<?php
class SpeechQgAction {
	private $text;
	public function __construct($text) {
		$this->text= $text;
	}
	function xfyun() {
		$daytime=strtotime('1970-1-1T00:00:00 UTC');
		$api = "http://ltpapi.xfyun.cn/v2/sa";
		$XAppid = "aba87a8f";
		$Apikey = "797ddbf217c93d25af79b3941ba87c96";
		$XCurTime =time();
		$XParam ="";
		$XCheckSum ="";
		
		$Param= array(
		    "type"=>"dependent",
		);
		
		
		$text = $this->text;
		$Post = array(
			'text' => $text,
		);
		
		$XParam = base64_encode(json_encode($Param));
		$XCheckSum = md5($Apikey.$XCurTime.$XParam);
		$headers = array();
		$headers[] = 'X-CurTime:'.$XCurTime;
		$headers[] = 'X-Param:'.$XParam;
		$headers[] = 'X-Appid:'.$XAppid;
		$headers[] = 'X-CheckSum:'.$XCheckSum;
		$headers[] = 'Content-Type:application/x-www-form-urlencoded; charset=utf-8';
		$rs = $this->http_request($api, $Post, $headers);
		$rs = json_decode($rs)->data;
		return $rs;
	}
	function http_request($url, $post_data, $headers) {
		$postdata = http_build_query($post_data);
		$options = array(
			'http' => array(
				'method' => 'POST',
				'header' => $headers,
				'content' => $postdata,
				'timeout' => 15*60
			)
		);
		$context = stream_context_create($options);
		$result = file_get_contents($url, false, $context);
		return $result;
	}
}
?>